package game.adm.controller;
import java.util.List;

import game.adm.dao.dto.WithdrawDTO;
import game.adm.entity.WithdrawEntityManager;
import game.adm.struts.form.WithdrawForm;
import game.web.base.Constants;
import game.web.base.StringUtils;
import projectx.core.base.ProjectXSystemException;
import projectx.core.base.ProjectXUserException;
import projectx.transaction.TransactionHandler;
import projectx.web.base.ProjectXDbTrxController;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;

public class WithdrawController extends ProjectXDbTrxController {

	protected WithdrawController(UserContext uc, ProjectXForm form) {
		super(uc, form);
	}

	@Override
	public Object execute() throws ProjectXUserException,
			ProjectXSystemException {
		debugBegin();

		UserContext uc = getUc();
		WithdrawForm form = (WithdrawForm)getForm();
		String operator = form.getOperator();
		String updateip = StringUtils.getString(uc.get(Constants.ADM_REQUEST_IP));
		
		if("0".equals(operator)){    //更新提现记录
			WithdrawEntityManager.update(form.getOrderID(), form.getStatus(),updateip);
		}else if("2".equals(operator)){     //查询提现记录详情
			WithdrawDTO dto = WithdrawEntityManager.getWithdrawByID(form.getOrderID());
			uc.put(Constants.ADM_WITHDRAW_RECORD, dto);
		}else{                           //提现记录查询
			List<WithdrawDTO> list = WithdrawEntityManager.list(form);
			uc.put(Constants.ADM_WITHDRAW_LIST, list);
		}

		debugEnd();
		return null;
	}

	public static Object execute(UserContext uc, ProjectXForm form)
			throws ProjectXUserException, ProjectXSystemException {
		return TransactionHandler.call(new WithdrawController(uc, form));
	}
}
